upstream {{ site.name }} {
    {{ site.upstream_method | default('least_conn') }};
{% for host in site.upstreams %}
    server                  {{ host }}.{{ elk_domain }}:{{ site.upstream_port | default(site.listen_port) }};
{% endfor %}
}

server {
    listen                  {{ site.listen_port | default('443') }} ssl;
    server_name             {{ site.name }}.{{ elk_domain }} *.{{ site.name }}.{{ elk_domain }};

    access_log              {{ elk_path.logs }}/nginx/{{ site.name }}/{{ site.name }}-access.log;
    error_log               {{ elk_path.logs }}/nginx/{{ site.name }}/{{ site.name }}-error.log;

    ssl_certificate         {{ elk_path.apps }}/nginx/ssl/{{ nginx_certificates.cert | basename }};
    ssl_certificate_key     {{ elk_path.apps }}/nginx/ssl/{{ nginx_certificates.key | basename }};

    location {{ site.location | default('/') }} {
        proxy_pass          {{ site.proxy_protocol }}://{{ site.name }};
        proxy_ssl_verify    {{ site.proxy_ssl_verify | default('off') }};
{% for header in (nginx_default_headers | sort) %}
        proxy_set_header    {{ header }};
{% endfor %}
{% if site.extra_headers is defined %}
{% for header in (site.extra_headers | sort) %}
        proxy_set_header    {{ header }};
{% endfor %}
{% endif %}
    }

    error_page              404 /404.html;
    location = /404.html {
        internal;
    }

    error_page              500 502 503 504 /50x.html;
    location = /50x.html {
        internal;
    }
}
